package CryptoPrim;

import ArithUtils.*;
import ArithmeticObjects.*;
import Utils.ByteTree;

/**
 * A class which represents a secret key (sk).
 * 
 * @author Itamar Carmel, nirhagin
 */
public class SecKey {

	// suppose sk = (x)
	private BTField<BigNumber> Zq; // Field of sk's elements
	private BTField<BigNumber>.BTElement x; // x

	/**
	 * Constructor of Secret Key from field and an element (x).
	 * 
	 * @param Zq
	 * @param x
	 */
	public SecKey(BTField<BigNumber> Zq, BTField<BigNumber>.BTElement x){
		this.Zq = Zq;
		this.x = x;
	}
	
	/**
	 * Convert BT to it's SK rep.
	 * 
	 * @param bt
	 * @param Zq
	 * @return SK(bt,Zq)
	 */
	public static SecKey getSecKey(ByteTree bt, BTField<BigNumber> Zq) {
		return new SecKey(Zq, Zq.getElement(bt));
	}

	/**
	 * Getter for x.
	 * 
	 * @return x
	 */
	public BTField<BigNumber>.BTElement getX() {
		return this.x;
	}
	
	/**
	 * Convert Secret Key to it's BT rep. 
	 * 
	 * @return BT(SK)
	 */
	public ByteTree getByteTreeRep(){
		return Zq.EtoByteTree(this.x);
	}

	/**
	 * Getter for field of this SK (Zq).
	 * 
	 * @return Zq
	 */
	public BTField<BigNumber> getField() {
		return this.Zq;
	}

}
